package cn.echogo.framework.location;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;

import cn.echogo.ipart.R;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class EGOverlay extends Overlay {

	private Context context;
	private GeoPoint geoPoint;
	private Bundle data;

	public EGOverlay(Context context, GeoPoint geoPoint) {
		this.context = context;
		this.geoPoint = geoPoint;
	}

	public void setData(Bundle data) {
		this.data = data;
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
		super.draw(canvas, mapView, shadow, when);
		// Translate the GeoPoint to screen pixels
		Point screenPts = new Point();
		mapView.getProjection().toPixels(geoPoint, screenPts);
		// add the marker
		Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.gps_icon);
		canvas.drawBitmap(bitmap, screenPts.x - bitmap.getWidth(), screenPts.y - bitmap.getHeight(), null);
		return true;
	}
	
	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		Address address = LocationUtil.getAddressByGeoPoint(context, geoPoint);
		String addressStr = LocationUtil.getAddressString(address);
		Toast.makeText(context, addressStr, Toast.LENGTH_SHORT).show();
		return true;
	}

}
